﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsForms
{
    public partial class ComboBoxPractice : Form
    {
        public ComboBoxPractice()
        {
            InitializeComponent();
        }

        private void cboFaculty_SelectedIndexChanged(object sender, EventArgs e)
        {
            
        }

        private void ComboBoxPractice_Load(object sender, EventArgs e)
        {
            cboFaculty.SelectedIndex = 0;
            lblSelectedFaculty.Text = cboFaculty.Text;
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            if (cboFaculty.Items.Contains(cboFaculty.SelectedItem.ToString()))
                lblSelectedFaculty.Text = cboFaculty.SelectedItem.ToString();
            else
            {
                cboFaculty.Items.Add(cboFaculty.Text);
                lblSelectedFaculty.Text = cboFaculty.Text;
            }
        }

        private void lblSelectedFaculty_Validating(object sender, CancelEventArgs e)
        {
            lblSelectedFaculty.Text = cboFaculty.SelectedItem.ToString();
        }

        private void lblSelectedFaculty_Validated(object sender, EventArgs e)
        {
            lblSelectedFaculty.Text = cboFaculty.SelectedItem.ToString();
        }
    }
}
